<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
// use Spatie\Activitylog\Traits\LogsActivity;

class WaterStorage extends Model
{
   use \App\Models\Traits\ScopeCompanySite;
   use \App\Models\Traits\Site;
  // use LogsActivity;
   
//   protected static $logFillable = true;
//   protected static $logName = 'storage';
//   // protected static $logAttributes = ['title', 'category_id'];
//   
//   //定义事件描述
//   public function getDescriptionForEvent(string $eventName)
//    {
//        switch ($eventName) {
//            case 'created':
//                $description = '入库单被创建';
//                break;
//            case 'updated':
//                $description = '入库单被更新';
//                break;
//            case 'deleted':
//                $description = '入库单被删除';
//                break;
//            default:
//                $description = $eventName;
//                break;
//        }
//        return $description;
//    }
   
    protected $fillable = [ "company_id", "site_id", "creater_uid", "creater_name", "status", "confirm_uid", "confirm_name" ];
    // protected $guarded = [];
    
    protected $casts = [
        'water_category_id' => 'integer',
        'company_id'=>'integer',
        'site_id'=>'integer',
        'creater_uid'=>'integer',
        'confirm_uid'=>'integer',
    ];
    
    public function getCompanyField() {
        return 'company_id';
    }
    
    public function getSiteField() {
        return 'site_id';
    }
    
    //项目信息
    public function companies() {
        return $this->hasOne('App\Models\Company', "Co_ID", "company_id");
    }
    //站点
    public function sites() {
        return $this->hasOne('App\Models\Site', "id", "site_id");
    }
    
    //入库商品
    public function shops() {
        return $this->belongsToMany('App\Models\WaterShop', 'water_storage_shop')->withPivot('num', 'price');
    }
    //出库商品
}
